/*
 * Copyright (C) 2011 by ayoung <ayoung.p@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.peaceb.ruletherain;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

/**
 * Log wrapper class
 */
public class Trace {
    public final static int ERROR   = 0;
    public final static int WARNING = 1;
    public final static int INFO    = 2;
    public final static int DEBUG   = 3;
    public final static int VERVOSE = 4;
    
    private static int mLogLevel = C.LOG_LEVEL;
    
    public static void e(String msg) {
        if (mLogLevel >= ERROR) {
            Log.e(C.TAG, msg);
        }
    }

    public static void e(Object obj, String msg) {
        if (mLogLevel >= ERROR) {
            if (obj == null)
            Log.e(C.TAG, ((obj != null) ? obj.getClass().getSimpleName() : "null") + ": " + msg);
        }
    }
    
    public static void w(String msg) {
        if (mLogLevel >= WARNING) {
            Log.w(C.TAG, msg);
        }
    }
    
    public static void w(Object obj, String msg) {
        if (mLogLevel >= WARNING) {
            Log.w(C.TAG, ((obj != null) ? obj.getClass().getSimpleName() : "null") + ": " + msg);
        }
    }
    
    public static void i(String msg) {
        if (mLogLevel >= INFO) {
            Log.i(C.TAG, msg);
        }
    }
    
    public static void i(Object obj, String msg) {
        if (mLogLevel >= INFO) {
            Log.i(C.TAG, ((obj != null) ? obj.getClass().getSimpleName() : "null") + ": " + msg);
        }
    }
    
    public static void d(String msg) {
        if (mLogLevel >= DEBUG) {
            Log.d(C.TAG, msg);
        }
    }
    
    public static void d(Object obj, String msg) {
        if (mLogLevel >= DEBUG) {
            Log.d(C.TAG, ((obj != null) ? obj.getClass().getSimpleName() : "null") + ": " + msg);
        }
    }
    
    public static void v(String msg) {
        if (mLogLevel >= VERVOSE) {
            Log.v(C.TAG, msg);
        }
    }
    
    public static void v(Object obj, String msg) {
        if (mLogLevel >= VERVOSE) {
            Log.v(C.TAG, ((obj != null) ? obj.getClass().getSimpleName() : "null") + ": " + msg);
        }
    }
    
    public static void toast(Context context, String msg) {
        if (mLogLevel == DEBUG) {
            Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
        }
    }
}
